package com.football.lottery.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCUtil
{
  public static final String MYSQL_URL = "jdbc:mysql://127.0.0.1:3306/footballlottery?useUnicode=true&amp;characterEncoding=utf8";
  public static final String MYSQL_USERNAME = "root";
  public static final String MYSQL_PASSWORD = "";
  
  public static final String POSTGRES_URL = "jdbc:postgresql://127.0.0.1:5432/footballlottery";
  public static final String POSTGRES_USERNAME = "lottery";
  public static final String POSTGRES_PASSWORD = "lottery";
  
  public static Connection getConnection(String url, String userName, String password)
  {
    Connection conn = null;
    try
    {
      Class.forName("com.mysql.jdbc.Driver");
      conn = DriverManager.getConnection(url, userName, password);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    return conn;
  }
  
  public static Connection getPGConnection()
  {
    Connection conn = null;
    try
    {
      Class.forName("org.postgresql.Driver");
      conn = DriverManager.getConnection(POSTGRES_URL, POSTGRES_USERNAME, POSTGRES_PASSWORD);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    return conn;
  }
  
  public static Connection getMySqlConnection()
  {
    Connection conn = null;
    try
    {
      Class.forName("com.mysql.jdbc.Driver");
      conn = DriverManager.getConnection(MYSQL_URL, MYSQL_USERNAME,MYSQL_PASSWORD);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    return conn;
  }

  public static void closeConnection(Connection conn)
  {
    try
    {
      if (conn != null)
      {
        conn.close();
      }
    }
    catch (SQLException e)
    {
      e.printStackTrace();
    }
  }
}
